import {HTTP} from '@/config/tongji.coffee'
import ipc from '~/lib/ipc.coffee'

_paq = window._paq = window._paq or []

### tracker methods like "setCustomDimension" should be called before "trackPageView" ###
_paq.push([
  'setCustomDimension'
  1
  await ipc.auto_update.ver_now()
])
_paq.push [ 'trackPageView' ]
_paq.push [ 'enableLinkTracking' ]
do ->
  u = HTTP
  _paq.push [
    'setTrackerUrl'
    u + 'matomo.php'
  ]
  _paq.push [
    'setSiteId'
    '1'
  ]
  d = document
  g = d.createElement('script')
  s = d.getElementsByTagName('script')[0]
  g.async = true
  g.src = u+'matomo.js'
  s.parentNode.insertBefore g, s
  return
### 谷歌统计
import {TID} from '../../../config/tongji.coffee'
import ipc from '~/lib/ipc.coffee'

hm = document.createElement('script')
hm.async = true

hm.src = 'https://www.googletagmanager.com/gtag/js?id='+TID
s = document.getElementsByTagName('script')[0]
s.parentNode.insertBefore hm, s

window.dataLayer = window.dataLayer || []


window.G = -> dataLayer.push(arguments)

for i from [
  [
    'config'
    TID
    user_id: localStorage.uid
  ]
  ['js', new Date()]
  [
    'event'
    'screen_view'
    {
      app_name: document.title
      screen_name : location.hash[1..]
      app_version: await ipc.auto_update.ver_now()
    }
  ]
]
  G(...i)
###
